/*
package com.demo.Main.StageOne;


import org.fusesource.jansi.AnsiConsole;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import static org.fusesource.jansi.Ansi.Color.GREEN;
import static org.fusesource.jansi.Ansi.Color.RED;
import static org.fusesource.jansi.Ansi.ansi;

*/
/**
 * 服务器列表会放到一个`server.txt`文件中，请从`server.txt`文件中读取到服务器列表并发送`http`请求确定服务器上的接收文件服务是否正常，并在控制台显示检测结果
 *//*

public class QDemo4 {
    private static int count = 0;

    private static final String RESET = "\u001B[0m";
    private static final String RED_BOLD = "\u001B[31;1m";
    private static final String GREEN_BOLD = "\u001B[32;1m";

    public static void main(String[] args) {
        AnsiConsole.systemInstall();
        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        executor.scheduleAtFixedRate(QDemo4::getTxt, 0, 10, TimeUnit.SECONDS);
    }

    */
/**
     * 获取文本文件中的内容
     *//*

    public static void getTxt() {
        File file = new File("localfile/server.txt");
        try (InputStream inputStream = new FileInputStream(file);
             BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
            byte[] bytes = bufferedInputStream.readAllBytes();
            String string = new String(bytes);
            String[] lines = string.split("\n");

            for (String s : lines) {
                try {
                    if (!isValidHttpUrl(s)) {
                        System.out.println(ansi().fg(RED).bold().a("无效URL: ").a(s).reset());
                        continue;
                    }

                    visit(s);
                } catch (Exception e) {
                    System.out.println(ansi().fg(RED).bold().a("处理URL失败: ").a(s).reset());
                }
            }

            count++;
            System.out.println("执行次数: " + count);

        } catch (IOException e) {
            System.out.println(e);
        }
    }

    */
/**
     * 访问网址
     *
     * @param string 网址
     *//*

    public static void visit(String string) {
        try {
            URL url = new URL(string);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; " +
                    "Win64; x64) AppleWebKit/537.36 (HTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36");

            // 获取响应状态码
            int responseCode = connection.getResponseCode();

            if (responseCode == 200) {
                System.out.println(ansi().fg(GREEN).bold().a(url).a(" Code: ").a(responseCode).reset());
            } else {
                System.out.println(ansi().fg(RED).bold().a(url).a(" Code: ").a(responseCode).a("连接失败！！！").reset());
            }

            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            StringBuilder html = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                html.append(inputLine);
            }

            in.close();
            connection.disconnect();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    */
/**
     * 判断是否是正确的http url
     *
     * @param url 标识互联网上资源位置的地址
     * @return boolean
     *//*

    public static boolean isValidHttpUrl(String url) {
        try {
            URL u = new URL(url);
            return "http".equals(u.getProtocol()) || "https".equals(u.getProtocol());
        } catch (Exception e) {
            return false;
        }
    }
}
*/
